
const app = getApp();

Component({
  options: {
    addGlobalClass: true
  },
  /**
 * 组件的初始数据
 */

  data: {
    buttom_note:'',
    yiqing:'',
    weather:'',
    user_number:0,
    inspector_number:0,
    day_in:0,
    day_out:0,
    swiperList: [
      'https://ae01.alicdn.com/kf/H14f699b028d044af9c4938145d2e71b73.jpg',
      'https://ae01.alicdn.com/kf/H14f699b028d044af9c4938145d2e71b73.jpg',
      'https://ae01.alicdn.com/kf/H14f699b028d044af9c4938145d2e71b73.jpg',
      'https://ae01.alicdn.com/kf/H14f699b028d044af9c4938145d2e71b73.jpg',
      'https://ae01.alicdn.com/kf/H14f699b028d044af9c4938145d2e71b73.jpg'
      ],
  },
attached: function(){
  // attached() {
    var that = this;
    this.setData({
      user_number:2
    })
    console.log("fuckssssss")
    wx.request({
      url:"http://172.17.25.145:8080/get_data_number",
      method:"GET",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function(res){
        console.log(res)
        console.log(res.data[0])
        that.setData({
          user_number:res.data[0],
          inspector_number:res.data[1],
          day_out:res.data[2],
          day_in:res.data[3]
        })
        console.log("user_number"+that.data.user_number)
      },
      fail:function(res){
        console.log("失败");
      }
    })
    wx.switchTab({
      url: '/pages/home/home',
    })
  },
  pageLifetimes: {
  },
  methods:{
    //温度打卡
    recordTemp: function () {
      wx.navigateTo({
        url: '/pages/wendu/wendu',
      })
    },
  
    //返工登记
  backWork: function () {
  wx.navigateTo({
    url: '/pages/backWork/backWork',
  })
  },
 
  //出门登记
  recordOut:function(){
   
    let tempCode;           //存放二维码返回的识别码为固定值 "scyf"
    let tempAddress;        //存放二维码返回的扫码地址 如"城南A区"
    wx.scanCode({
      onlyFromCamera: true,           //只能从相机扫码
      scanType: ['qrCode'],           //只能扫二维码
      success: (res) => {
        console.log(res)
        tempCode = res.result.substring(1, 5)      //提取1-5位字符
        console.log(tempCode)
        console.log(getApp().globalData.room_id)
        tempAddress = res.result.substring(5)         //提取第五位以后的字符
        if (tempCode!="\"roo") {     //对识别码进行校验，正确的二维码才能进行下一步
          console.log("验证失败")       //验证失败，弹窗提示
          wx.showModal({
            title: '提示',
            content: '请扫描正确的二维码',
          })
        }
        else {
          wx.vibrateShort()
          var objs = JSON.parse(res.result)
          console.log(objs)
          for(var key in objs){
            console.log(key+":"+objs[key])
            if(key=="room_id"){
              console.log("设置房间号")
              getApp().globalData.room_id = objs[key]
            }else if(key=="id_number"){
              console.log("设置身份证号")
              getApp().globalData.id_number=objs[key]
            }else if(key=="phone"){
              getApp().globalData.phone= objs[key]
            }else if(key=="openid"){
              getApp().globalData.Uopenid = objs[key]
            }else if(key=="sex"){
              getApp().globalData.sex = objs[key]
            }else if(key == "name"){
              getApp().globalData.name = objs[key]
            }else if(key=="year"){
              getApp().globalData.year = objs[key]
            }else{
              getApp().globalData.health = objs[key]
            }
          }
          console.log(getApp().globalData.Uopenid)
          console.log("验证成功")             //验证成功，进行页面跳转
          wx.navigateTo({
            url: '/pages/out/out?title=' + res.result.substring(5)
          })
        }
      },
    })
  },
//出门登记
recordIn:function(){
  wx.request({
    url:"http://172.17.25.145:8080/get_data_number",
    method:"GET",
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function(res){
      console.log(res)
      console.log(res.data[0])
      that.setData({
        user_number:res.data[0],
        inspector_number:res.data[1],
        day_out:res.data[2],
        day_in:res.data[3]
      })
      console.log("user_number"+that.data.user_number)
    },
    fail:function(res){
      console.log("失败");
    }
  })
  let tempCode;           //存放二维码返回的识别码为固定值 "scyf"
  let tempAddress;        //存放二维码返回的扫码地址 如"城南A区"
  wx.scanCode({
    onlyFromCamera: true,           //只能从相机扫码
    scanType: ['qrCode'],           //只能扫二维码
    success: (res) => {
      console.log(res)
      tempCode = res.result.substring(1, 5)      //提取1-5位字符
      console.log(tempCode)
      console.log(getApp().globalData.room_id)
      tempAddress = res.result.substring(5)         //提取第五位以后的字符
      if (tempCode!="\"roo") {     //对识别码进行校验，正确的二维码才能进行下一步
        console.log("验证失败")       //验证失败，弹窗提示
        wx.showModal({
          title: '提示',
          content: '请扫描正确的二维码',
        })
      }
      else {
        wx.vibrateShort()
        var objs = JSON.parse(res.result)
        console.log(objs)
        for(var key in objs){
          console.log(key+":"+objs[key])
          if(key=="room_id"){
            console.log("设置房间号")
            getApp().globalData.room_id = objs[key]
          }else if(key=="id_number"){
            console.log("设置身份证号")
            getApp().globalData.id_number=objs[key]
          }else if(key=="phone"){
            getApp().globalData.phone= objs[key]
          }else if(key=="openid"){
            getApp().globalData.Uopenid = objs[key]
          }else if(key=="sex"){
            getApp().globalData.sex = objs[key]
          }else if(key == "name"){
            getApp().globalData.name = objs[key]
          }else if(key=="year"){
            getApp().globalData.year = objs[key]
          }else{
            getApp().globalData.health = objs[key]
          }
        }
        console.log(getApp().globalData.Uopenid)
        console.log("验证成功")             //验证成功，进行页面跳转
        wx.navigateTo({
          url: '/pages/in/in?title=' + res.result.substring(5)
        })
      }
    },
  })
},
},
// })
})
